/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bio.jpa.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Diego
 */
@Entity
@Table(name = "project", catalog = "biodb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Project.findAll", query = "SELECT p FROM Project p"),
    @NamedQuery(name = "Project.findByPrjId", query = "SELECT p FROM Project p WHERE p.prjId = :prjId"),
    @NamedQuery(name = "Project.findMyGb", query = "SELECT gb FROM GenBank gb WHERE gb.prjFk.prjId = :prjId"),
    @NamedQuery(name = "Project.findMyUsers", query = " select u from User u where u.userId in (SELECT m.projectHasUserPK.userUserId  FROM ProjectHasUser m where m.projectHasUserPK.projectPrjId=:prjId) "),
    @NamedQuery(name = "Project.findByPrjName", query = "SELECT p FROM Project p WHERE p.prjName = :prjName"),
    @NamedQuery(name = "Project.findByPrjDesc", query = "SELECT p FROM Project p WHERE p.prjDesc = :prjDesc"),
    @NamedQuery(name = "Project.findByPrjCreation", query = "SELECT p FROM Project p WHERE p.prjCreation = :prjCreation"),
    @NamedQuery(name = "Project.findByPrjUpdate", query = "SELECT p FROM Project p WHERE p.prjUpdate = :prjUpdate")})
public class Project implements Serializable {

    @JoinColumn(name = "project_status_fk", referencedColumnName = "idprj_sts")
    @ManyToOne(optional = false)
    private ProjectStatus projectStatus;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "project")
    private List<Fasta> fastaList = new ArrayList<Fasta>();
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(name = "prj_id")
    private Integer prjId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "prj_name")
    private String prjName;
    @Size(max = 45)
    @Column(name = "prj_desc")
    private String prjDesc;
    @Basic(optional = false)
    @NotNull
    @Column(name = "prj_creation")
    @Temporal(TemporalType.TIMESTAMP)
    private Date prjCreation;
    @Column(name = "prj_update")
    @Temporal(TemporalType.TIMESTAMP)
    private Date prjUpdate;
    @JoinColumn(name = "created_by", referencedColumnName = "user_id")
    @ManyToOne(optional = false)
    private User createdBy;
    @JoinColumn(name = "updated_by", referencedColumnName = "user_id")
    @ManyToOne
    private User updatedBy;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "prjFk")
    private List<GenBank> genBankList;
    @JoinTable(name = "project_has_audit_log", joinColumns = {
        @JoinColumn(name = "prj_fk", referencedColumnName = "prj_id")}, inverseJoinColumns = {
        @JoinColumn(name = "log_fk", referencedColumnName = "id_log")})
    @ManyToMany
    private List<AuditLog> auditLogList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "project")
    private List<ProjectHasUser> projectHasUserList;

    @XmlTransient
    public List<AuditLog> getAuditLogList() {
        return auditLogList;
    }

    public void setAuditLogList(List<AuditLog> auditLogList) {
        this.auditLogList = auditLogList;
    }

    @XmlTransient
    public List<ProjectHasUser> getProjectHasUserList() {
        return projectHasUserList;
    }

    public void setProjectHasUserList(List<ProjectHasUser> projectHasUserList) {
        this.projectHasUserList = projectHasUserList;
    }

    public Project() {
    }

    public Project(Integer prjId) {
        this.prjId = prjId;
    }

    public Project(Integer prjId, String prjName, Date prjCreation) {
        this.prjId = prjId;
        this.prjName = prjName;
        this.prjCreation = prjCreation;
    }

    public Integer getPrjId() {
        return prjId;
    }

    public void setPrjId(Integer prjId) {
        this.prjId = prjId;
    }

    public String getPrjName() {
        return prjName;
    }

    public void setPrjName(String prjName) {
        this.prjName = prjName;
    }

    public String getPrjDesc() {
        return prjDesc;
    }

    public void setPrjDesc(String prjDesc) {
        this.prjDesc = prjDesc;
    }

    public Date getPrjCreation() {
        return prjCreation;
    }

    public void setPrjCreation(Date prjCreation) {
        this.prjCreation = prjCreation;
    }

    public Date getPrjUpdate() {
        return prjUpdate;
    }

    public void setPrjUpdate(Date prjUpdate) {
        this.prjUpdate = prjUpdate;
    }

    public User getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public User getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(User updatedBy) {
        this.updatedBy = updatedBy;
    }

    @XmlTransient
    public List<GenBank> getGenBankList() {
        return genBankList;
    }

    public void setGenBankList(List<GenBank> genBankList) {
        this.genBankList = genBankList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (prjId != null ? prjId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Project)) {
            return false;
        }
        Project other = (Project) object;
        if ((this.prjId == null && other.prjId != null) || (this.prjId != null && !this.prjId.equals(other.prjId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bio.jpa.entities.Project[ prjId=" + prjId + " ]";
    }

    public ProjectStatus getProjectStatus() {
        return projectStatus;
    }

    public void setProjectStatus(ProjectStatus projectStatus) {
        this.projectStatus = projectStatus;
    }

    @XmlTransient
    public List<Fasta> getFastaList() {
        return fastaList;
    }

    public void setFastaList(List<Fasta> fastaList) {
        this.fastaList = fastaList;
    }
}
